package com.li.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.li.drug.entity.Druginfo;
import com.li.drug.mapper.DruginfoMapper;
import com.li.drug.service.DruginfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;

/**
 * 供应商service实现类
 */
@Service
public class DruginfoServiceImpl extends ServiceImpl<DruginfoMapper, Druginfo> implements DruginfoService {

    @Autowired
    DruginfoMapper druginfoMapper;

    @Override
    public Page<Druginfo> selectDruginfoPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Druginfo> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(param)){
            wrapper.like("name",param);
        }
        Page<Druginfo> page = new Page<>(pageNum,pageSize);
        return druginfoMapper.selectPage(page,wrapper);
    }

    @Override
    public int addDruginfo(Druginfo druginfo) {
       return druginfoMapper.insert(druginfo);
    }

    @Override
    public int editDruginfo(Druginfo druginfo) {
        return druginfoMapper.updateById(druginfo);
    }

    @Override
    public Druginfo getDruginfoById(Integer id) {
        return druginfoMapper.selectById(id);
    }

    @Override
    public int delDruginfoById(Integer id) {
        return druginfoMapper.deleteById(id);
    }
}
